package com.itheima.day15.TCP.test9;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.Scanner;

public class ChatOutput implements Runnable{

    Socket accept;

    public ChatOutput( Socket accept) {
        this.accept = accept;
    }

    @Override
    public void run() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String s = sc.nextLine();
            if (s != null) {
                BufferedWriter osr = null;
                try {

                    osr = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
                    osr.write(accept.getLocalPort()+"-->"+s);
                    osr.newLine();
                    osr.flush();
                    //accept.shutdownOutput();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}
